/**
 * author: MaHX
 * date: 2019/10/23/13:46
 * description:
 * HashMap使用三大集合和三种迭代子来轮询其Key、Value和Entry对象
 **/

import java.util.*;

public class HashMapExam {
    public static void main(String[] args) {
        Map map = new HashMap(16);
        for (int i = 0; i < 15; i++) {
            map.put(i, new String(new char[]{(char) ('A'+ i)}));
        }
        System.out.println("======keySet=======");
        Set set = map.keySet();
        Iterator iterator = set.iterator();
        while (iterator.hasNext()) {
            System.out.println(iterator.next());
        }
        System.out.println("======values=======");
        Collection values = map.values();
        Iterator stringIterator=values.iterator();
        while (stringIterator.hasNext()) {
            System.out.println(stringIterator.next());
        }
        System.out.println("======entrySet=======");
        //forEach方法遍历
        for (Object entry : map.entrySet()) {
            System.out.println(entry);
        }
        //iterator遍历 ①
        Set set1 = map.entrySet();
        Iterator iterator1 = set1.iterator();
        while (iterator1.hasNext()){
            System.out.println(iterator1.next());
        }
        //iterator遍历 ②
        Iterator iterator2 = map.entrySet().iterator();
        while (iterator2.hasNext()){
            System.out.println(iterator2.next());
        }
    }
}
